#include <stdio.h>
#include <stdlib.h>

#define MAX_INT 1000001
#define SELECTED    1
#define UNSELECT    0

int N = 0;
int** matrix = NULL;
int s[200];

void init(int initval)
{
    int i = 0, j= 0;
    matrix = (int**)malloc(N*sizeof(int*));
    for(i = 0; i < N; i++)
    {
        matrix[i] = (int*)malloc(N*sizeof(int));
        for(j = 0; j < N; j++)
        {
            matrix[i][j] = initval;
        }
    }
}

void findv(int* vertexs, int* vertexd)
{
    int i = 0, j = 0;
    int min = MAX_INT;

    for(i = 0; i < N; i++)
    {
        if(s[i] == 0)
        {
            continue;
        }
        for(j = 0; j < N ; j++)
        {
            if(s[j] == 1)
            {
                continue;
            }
            if(min > matrix[i][j])
            {
                min = matrix[i][j];
                *vertexs = i;
                *vertexd = j;
            }
        }
    }
}

void getmin()
{
    int i = 0;
    int vertexs = 0, vertexd = 0;
    int vertexcount = N;
    int minlen = 0;

    s[0] = 1;
    for(i = 1; i < N; i++)
    {
        s[i] = 0;
    }
    vertexcount--;

    while(vertexcount > 0)
    {
        findv(&vertexs, &vertexd);
        s[vertexd] = 1;
        minlen += matrix[vertexs][vertexd];
        vertexcount--;
    }
    printf("%d\n", minlen);
}


void process()
{
    int i = 0, j = 0;
    while(scanf("%d", &N) != EOF)
    {
        init(MAX_INT);
        for(i = 0; i < N; i++)
        {
            for(j = 0; j < N; j++)
            {
                scanf("%d", &matrix[i][j]);
            }
        }
        getmin();
    }
}

int main()
{
    //freopen("bin\\debug\\in.txt", "r", stdin);

    process();

    return 0;
}
